package com.zhaokuner.springboot.config;

import com.zhaokuner.springboot.refresh.RefreshAfterRunner;
import com.zhaokuner.springboot.refresh.RefreshScopeLaunch;
import com.zhaokuner.springboot.zk.CuratorClientRefreshLaunch;
import com.zhaokuner.springboot.zk.ZkRefreshLog;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * Description:刷新配置
 * <p>
 * Copyright: 2018-现在 北京掌通未来科技有限公司
 * <p>
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/7/27 11:29
 */
@Configuration
@ConditionalOnProperty(prefix = "spring.cloud.config", value = "enabled", havingValue = "true")
public class RefreshConfig {

    @Bean
    @ConditionalOnProperty(prefix = "spring.cloud.config.zkRefreshLog", value = "enabled", havingValue = "true")
    public ZkRefreshLog zkRefreshLog(RefreshAfterRunner refreshAfterRunner) {
        ZkRefreshLog log = new ZkRefreshLog();
        refreshAfterRunner.addRunner(log);
        return log;
    }

    @Bean
    public RefreshAfterRunner refreshAfterRunner() {
        RefreshAfterRunner refreshAfterRunner = new RefreshAfterRunner();
        return refreshAfterRunner;
    }

    @Bean
    public RefreshScopeLaunch refreshScopeLaunch() {
        RefreshScopeLaunch launch = new RefreshScopeLaunch();
        return launch;
    }

    @Bean
    public CuratorClientRefreshLaunch curatorClientRefreshLaunch() {
        return new CuratorClientRefreshLaunch();
    }

}
